Title: SQL BT (By-BKK) / 09 Expressions
Tags: Obsidian_to_Anki

Q: What is an expression in SQL queries?
A: A statement that computes or transforms column values using logic, math, or functions

Q: True or False: You can use mathematical, string, and date functions in SQL expressions.
A: True

Q: What does the AS keyword do in SQL expressions?
A: Gives a descriptive alias to a computed column

Q: How does using expressions save time in working with query results?
A: It transforms data as part of the query to avoid post-processing

Q: Can columns and tables have aliases in SQL?
A: Yes

Q: What does ABS() do in a SQL expression?
A: Returns the absolute value of a number

Q: How do you select half the value of a column in SQL?
A: SELECT column / 2 AS half_column FROM table

Q: Write an SQL query for combined sales in millions.
A: SELECT title, (domestic_sales + international_sales) / 1000000 AS combined_sales_millions FROM movies INNER JOIN boxoffice ON movies.id = boxoffice.movie_id

Q: Write an SQL query to show movie ratings as a percent.
A: SELECT title, rating * 10 AS rating_percent FROM movies INNER JOIN boxoffice ON movies.id = boxoffice.movie_id

Q: How can you list movies released in even years using SQL?
A: SELECT title FROM movies WHERE year % 2 = 0

Q: Reverse card: A computed or transformed column value using math, logic, or functions
A: What is an expression in SQL?

Q: Reverse card: AS
A: What SQL keyword assigns a name to an expression or column alias?

Q: Reverse card: True
A: Can mathematical, string, and date functions be used in SQL expressions?

Q: Reverse card: SELECT title FROM movies WHERE year % 2 = 0
A: How do you find movies released in even years with SQL?

Q: Reverse card: SELECT column / 2 AS half_column FROM table
A: How do you select half of a column's value in SQL?